package com.mc.mq.rocketmq.delay;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer=new DefaultMQProducer("group1");
        producer.setNamesrvAddr("192.168.3.31:9876;192.168.3.32:9876;");
        producer.start();
        for (int i = 0; i < 10; i++) {
            Message msg=new Message("DelayTopic","Tag1",("Hello World"+i).getBytes(StandardCharsets.UTF_8));
            msg.setDelayTimeLevel(2);//设定延时时间
            SendResult result = producer.send(msg);
            SendStatus status = result.getSendStatus();
            System.out.println(result);
        }
    }
}
